package com.example.wx.Dao;

import com.example.wx.Entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public interface UserDao extends JpaRepository<User,Integer> {
    @Modifying(clearAutomatically = true)
    @Query(value = "update user set name=?2 ,account=?3,password=?4,houseid=?5,cardid=?6 where openid=?1",nativeQuery = true)
    public void update(@Param("openid") String openid, @Param("name") String name,
                       @Param("account") String account,@Param("password") String password,
                       @Param("houseid")String houseid,@Param("cardid") String cardid);


    @Modifying(clearAutomatically = true)
    @Query(value = "update user set power=1 where openid=?1",nativeQuery = true)
    public void power(@Param("openid") String openid);

    @Modifying(clearAutomatically = true)
    @Query(value = "update user set power=0 where openid=?1",nativeQuery = true)
    public void power1(@Param("openid") String openid);

    @Modifying(clearAutomatically = true)
    @Query(value = "update user set outcounts=outcounts+1 where cardid=?1",nativeQuery = true)
    public void updatecount(@Param("cardid") String cardid);

    @Modifying(clearAutomatically = true)
    @Query(value = "update user set status=1 where openid=?1",nativeQuery = true)
    public void lock(@Param("openid") String openid);

    @Modifying(clearAutomatically = true)
    @Query(value = "update user set status=0 where openid=?1",nativeQuery = true)
    public void unlock(@Param("openid") String openid);
}

